package com.congee02.bt.dfs.top2bottom;

import com.congee02.bt.TreeNode;

import java.util.*;

public class RightSideView {

    public List<Integer> rightSideView(TreeNode root) {

        List<Integer> ans = new ArrayList<>();

        dfs(root, ans, 0);

        return ans;
    }

    private void dfs(TreeNode root, List<Integer> ans, int level) {

        if (root == null) {
            return;
        }

        if (level == ans.size()) {
            ans.add(root.val);
        }

        dfs(root.right, ans, level + 1);
        dfs(root.left, ans, level + 1);

    }

}
